<template>
  <div class="adminSet">
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-form-item label="分类名称：" prop="resourceName">
        <el-input v-model="ruleForm.resourceName"></el-input>
      </el-form-item>
      <el-form-item label="排序号：" prop="sort">
        <el-input v-model="ruleForm.sort"></el-input>
      </el-form-item>

      <el-form-item label="商品数" prop="link">
        <el-input-number v-model="num" @change="handleChange" :min="1" :max="10" label="描述文字"></el-input-number>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="ruleForm.state">
          <el-option label="禁用" value="0"></el-option>
          <el-option label="启用" value="1"></el-option>
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')" size="mini">保存</el-button>

        <el-button @click="resetForm('ruleForm')" size="mini">取消</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { addmenus, changemenus } from "@/api/platformmanage";
import qs from "qs";
export default {
  data() {
    return {
      radio: "1",
      ifMain: "0",
      isRight: "0",
      num: 1,
      ruleForm: {
        resourceReq: "",
        resourceUrl: "",
        resourceName: "",
        menuId: "",
        upMenuId: "",
        resourceDesc: "",
        upResourceReq: ""
      },
      rules: {
        resourceName: [
          { required: true, message: "请输入菜单名称", trigger: "blur" }
        ],
        sort: [{ required: true, message: "请输入排序号", trigger: "blur" }]

        // password: [{ required: true }]
      }
    };
  },
  mounted() {
    console.log("lll");
    console.log(this.$route.params, "ppp");
    if (this.$route.params) {
      this.ruleForm.resourceName = this.$route.params.v.resourceName;

      this.ruleForm.resourceLevel = this.$route.params.v.resourceLevel;

      this.ruleForm.resourceUrl = this.$route.params.v.resourceUrl;
    }
  },
  methods: {
    resetForm() {
      this.$router.push("/menuManagement");
    },
    handleChange(value) {
      console.log(value);
    },
    submitForm() {
      if (this.$route.params.button === 1) {
        this.ruleForm.upMenuId = this.$route.params.v.menuId;
        console.log(this.$route.params.v.resourceReq, "ooo");
        addmenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息添加成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
      } else if (this.$route.params.button === 0) {
        // this.ruleForm.upMenuId = this.$route.params.v.menuId;
        this.ruleForm.menuId = this.$route.params.v.menuId;
        console.log(this.$route.params, "ppppp");
        changemenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息修改成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
        console.log("oo");
      } else if (this.$route.params.button === 2) {
        // this.ruleForm.upMenuId = this.$route.params.v.menuId;
        // this.ruleForm.menuId = this.$route.params.v.menuId;
        // console.log(this.$route.params, "ppppp");
        addmenus(this.ruleForm).then(res => {
          this.$message({
            showClose: true,
            message: "菜单信息添加成功",
            type: "success"
          });
          this.$router.push("/menuManagement");
        });
        console.log("oo");
      }
    }
  }
};
</script>>

<style lang="less" scoped>
.adminSet {
  border: 1px solid #ebeef5;
  margin-left: 150px;
  padding: 50px 0px 20px 150px;
  width: 55%;
}
.el-input {
  position: relative;
  font-size: 14px;
  display: inline-block;
  width: 62%;
}
</style>
